package cn.hxzy.teacher.examination.mapper;

import cn.hxzy.teacher.examination.pojo.Examination;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;


import java.util.List;
import java.util.Map;

@Component
public interface examinationMapper extends BaseMapper<Examination> {
    @Select("SELECT subject_id,subject_name,`option_a`,`option_b`,`option_c`,`option_d`,`option_e`,`option_f`,subject_answer,subject_type,subject_major,subject_image,creator \n" +
            "FROM sys_subject ")
    List<Map> selectSubject2();


    @Select("SELECT direction_id, direction_name FROM sys_direction")
    List<Map> selectDirections();

    //插入试卷信息
    @Insert("INSERT INTO \n" +
            "sys_examination\n" +
            "(examination_name,\n" +
            "examination_teacher_id,\n" +
            "examination_type,\n" +
            "examination_score)\n" +
            " VALUE(#{examinationName},#{examinationTeacherId},#{examinationType},#{examinationScore})")
    int insertExamination(Examination map);

    @Select("SELECT examination_id\n" +
            "        FROM sys_examination WHERE\n" +
            "        examination_name=#{examinationName}\n" +
            "        AND examination_teacher_id= #{examinationTeacherId}\n" +
            "        AND examination_type=#{examinationType}\n" +
            "        AND examination_score=#{examinationScore}")
    Integer selectExaminationId(Examination map);
    //修改试卷信息
    @Update("UPDATE sys_examination SET" +
            " examination_teacher_id=#{examinationTeacherId}," +
            "examination_name=#{examinationName}," +
            "examination_score=#{examinationScore} " +
            "WHERE examination_id=#{examinationId}")
    int updataExaminationInfo(Map map);

    @Delete("DELETE FROM sys_questiones WHERE questiones_examination=#{examinationId} ")
     int deleteQuestiones(Integer examinationId);


    //插入试卷的详细信息
    int insertExaminationSubject(List<Map> map);

    //查询标签
    @Select("SELECT * FROM sys_subject_label WHERE major_id=#{major_id}")
    List<Map> selectAllTag(Integer major_id);

    //条件查询试题
    List<Map> selectsubjects01(Map map);

    //查询试卷的详细信息
    @Select("SELECT examination_name,examination_teacher_id,examination_type,examination_score FROM sys_examination WHERE examination_id=#{examination_id}")
    Map selectExaminationSubject(Integer examination_id);

    //查询试卷的所有题目
    @Select("SELECT questiones_subject,`questiones_score` FROM sys_questiones WHERE questiones_examination=#{questiones_examination}")
    List<Map> selectQuestionesSubject(Integer questiones_examination);

    //查询试卷的所有题目
    @Select("SELECT subject_id,subject_name,\n" +
            "        `option_a`,\n" +
            "        `option_b`,\n" +
            "        `option_c`,\n" +
            "        `option_d`,\n" +
            "        `option_e`,\n" +
            "        `option_f`,\n" +
            "        subject_answer,\n" +
            "        subject_type,\n" +
            "        subject_major,\n" +
            "        subject_image,\n" +
            "        creator,\n" +
            "questiones_score,\n"+
            "questiones_subject\n"+
            "        FROM sys_subject,sys_questiones\n" +
            "        WHERE sys_subject.subject_id = sys_questiones.questiones_subject\n" +
            "        AND questiones_subject=#{questiones_subject}")
    List<Map> selectSubjectmessage(Map map);

    int selectsubjects01Count(Map map);
}
